/*-
 * CBS.java
 *
 * $LastChangedBy: stein $
 * $LastChangedRevision: 95 $
 * $LastChangedDate: 2007-02-13 16:19:24 +0000 (Tue, 13 Feb 2007) $
 * $HeadURL: svn://localhost/SMS/src/com/googlecode/attention/sms/pdu/CBS.java $
 *
 * Copyright (c) 2007, Stein Gunnar Bakkeby
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Stein Gunnar Bakkeby nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.googlecode.attention.sms.pdu;

/**
 * CBS Data Coding Scheme. 
 * <BR>Defined in 3GPP TS 23.038 version 5.1.0 Release 5.
 *
 * @author Stein Gunnar Bakkeby
 */
public enum CBS {
 
  /* Static field values */
  /** German language. */
  GERMAN(0, "German"),
  /** English language. */
  ENGLISH(1, "English"),
  /** Italian language. */
  ITALIAN(2, "Italian"),
  /** French language. */
  FRENCH(3, "French"),
  /** Spanish language. */
  SPANISH(4, "Spanish"),
  /** Dutch language. */
  DUTCH(5, "Dutch"),
  /** Swedish language. */
  SWEDISH(6, "Swedish"),
  /** Danish language. */
  DANISH(7, "Danish"),
  /** Portuguese language. */
  PORTUGUESE(8, "Portuguese"),
  /** Finnish language. */
  FINNISH(9, "Finnish"),
  /** Norwegian language. */
  NORWEGIAN(10, "Norwegian"),
  /** Greek language. */
  GREEK(11, "Greek"),
  /** Turkish language. */
  TURKISH(12, "Turkish"),
  /** Hungarian language. */
  HUNGARIAN(13, "Hungarian"),
  /** Polish language. */
  POLISH(14, "Polish"),
  /** Unspecified language. */
  LANGUAGE_UNSPECIFIED(15, "Unspecified Language"),
  
  /** Czech language. */
  CZECH(0, "Czech"),
  /** Hebrew language. */
  HEBREW(1, "Hebrew"),
  /** Arabic language. */
  ARABIC(2, "Arabic"),
  /** Russian language. */
  RUSSIAN(3, "Russian"),
  /** Icelandic language. */
  ICELANDIC(4, "Icelandic");
  
  /**
   * The CBS integer value.
   */
  public final int value;
  private final String language;
  
  private CBS(final int value, final String language) {
    this.value = value;
    this.language = language;
  }
  
  private static final CBS[] orderList = new CBS[] {
      GERMAN,ENGLISH,ITALIAN,FRENCH,DUTCH,SWEDISH,DANISH,PORTUGUESE,FINNISH,
      NORWEGIAN,GREEK,TURKISH,HUNGARIAN,POLISH,LANGUAGE_UNSPECIFIED,CZECH,
      HEBREW,ARABIC,RUSSIAN,ICELANDIC
  };
  
  /**
   * This will return a textual representation of this enum.
   * 
   * @return The language represented by this enum.
   */
  public String toString() {
    return language;
  }
  
  /**
   * This will return the CBS enum based on an integer value. This method
   * will return LANGUAGE_UNSPECIFIED if the integer value is not recognized.
   * 
   * @param cbs The CBS integer value
   * @return The CBS enum
   */
  public static CBS parse(final int cbs) {
    if (cbs < 0 || cbs > 20) {
      return LANGUAGE_UNSPECIFIED;
    }
    return orderList[cbs];
  }
  
  /**
   * This will return the CBS enum based on a string value.
   * 
   * @param cbs Any CBS language string values.
   * @return The corresponding CBS enum, or LANGUAGE_UNSPECIFIED if error.
   */
  public static CBS parse(final String cbs) {
    final String cbsUpperCase = cbs.trim().toUpperCase();
    if (cbs.startsWith("UNSPECIFIED")) return LANGUAGE_UNSPECIFIED;
    return CBS.valueOf(cbsUpperCase);
  }
}